package com.qf.service.impl;

import com.qf.bean.Menu;
import com.qf.dao.MenuMapper;
import com.qf.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * IntelliJ IDEA -> person
 * 2019/11/23 22:02
 *
 * @author zmyao
 * 别看，我是渣渣。
 */
@Service
public class MenuServiceImpl implements MenuService {
    @Autowired
   private MenuMapper menuMapper;
/*    @Override
    public List<Menu> selectAllMenu() {
        return menuMapper.selectAllMenu();
    }*/

    @Override
    public List<Menu> findAllMenus() {
        List<Menu> menus = menuMapper.selectAllMenu();
        for (Menu menu : menus) {
            System.out.println("id"+menu.getMenuid());
        }
        List <Menu> firstMenus = new ArrayList<>();
        for (Menu menu : menus) {
            if (menu.getUpmenuid() == 0){//一级菜单
                List<Menu>   secondMenus = new ArrayList<>();
                for (Menu second : menus) {
                    if (second.getUpmenuid() == menu.getMenuid()){//二级菜单
                        secondMenus.add(second);
                    }
                }
                menu.setSecondMenu(secondMenus);
                firstMenus.add(menu);
            }
        }
        return firstMenus;
    }
}
